package com.arsl.client.view;

import com.arsl.client.event.LoginEvent;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class Banner extends Composite {

	private boolean isLoggedIn = false;
	private String userName;
	private HandlerManager eventBus;

	private static BannerUiBinder uiBinder = GWT.create(BannerUiBinder.class);

	@UiField
	FlowPanel onLoginPanel;

	@UiField
	FlowPanel onLogoutPanel;

	@UiField
	Label lblWelcome;

	@UiField
	Button btnSignOut;

	@UiHandler("btnSignOut")
	public void signOutClickHandler(ClickEvent event) {
		LoginEvent ev = new LoginEvent();
		ev.setEventType(LoginEvent.LOGOUT);
		eventBus.fireEvent(ev);

	}

	interface BannerUiBinder extends UiBinder<Widget, Banner> {
	}

	public Banner() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public HandlerManager getEventBus() {
		return eventBus;
	}

	public void setEventBus(HandlerManager eventBus) {
		this.eventBus = eventBus;
	}

	public boolean isLoggedIn() {
		return isLoggedIn;
	}

	public void setLoggedIn(boolean isLoggedIn) {
		this.isLoggedIn = isLoggedIn;
		onLogoutPanel.setVisible(!isLoggedIn);
		onLoginPanel.setVisible(isLoggedIn);
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
		lblWelcome.setText("Welcome " + userName);
	}

}
